<template>
  <div class="app">
    <van-sticky>
      <van-nav-bar
        title="从业年限"
        left-text="返回"
        left-arrow
        fixed
        @click-left="onClickLeft"
      ></van-nav-bar>
    </van-sticky>
    <div class="main">
      <van-cell-group inset>
        <van-field v-model="year" label="年：" placeholder="请输入年限" />
      </van-cell-group>
      <van-cell-group inset>
        <van-field name="stepper" label="月：">
          <template #input>
            <van-stepper v-model="month" />
          </template>
        </van-field>
      </van-cell-group>
      <div class="submit">
        <van-button size="small" type="primary" @click="submit"
          >提交</van-button
        >
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref, computed } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { updateEInquiryItem } from './api'
import { Notify } from 'vant'

const router = useRouter()
const route = useRoute()

let year = ref<string>('0')

let month = ref<number>(0)

const period = computed(() => {
  return parseInt(year.value) + parseFloat('' + month.value / 10)
})

const submit = () => {
  let params = {
    id: route.query.id,
    period: period.value,
  }
  updateEInquiryItem(params).then((res) => {
    Notify({ type: 'success', message: '修改成功' })
    router.push({
      path: '/consultManage',
    })
  })
}

const onClickLeft = () => {
  router.push({
    path: '/consultManage',
  })
}
</script>

<style lang="less" scoped>
.app {
  .main {
    padding-top: 56px;

    .submit {
      margin-top: 20px;
      text-align: center;
    }
  }
}
</style>
